      INTEGER          FUNCTION IDAMAX( N, DX, INCX )
*
*     finds the index of element having max. absolute value.
*     jack dongarra, linpack, 3/11/78.
*
*     .. Scalar Arguments ..
      INTEGER                           INCX, N
*     ..
*     .. Array Arguments ..
      DOUBLE PRECISION                  DX( 1 )
*     ..
*     .. Local Scalars ..
      INTEGER                           I, IX
      DOUBLE PRECISION                  DMAX
*     ..
*     .. Intrinsic Functions ..
      INTRINSIC                         DABS
*     ..
*     .. Executable Statements ..
*
      IDAMAX = 0
      IF( N.LT.1 )
     $   RETURN
      IDAMAX = 1
      IF( N.EQ.1 )
     $   RETURN
      IF( INCX.EQ.1 )
     $   GO TO 30
*
*        code for increment not equal to 1
*
      IX = 1
      IF( INCX.LT.0 )
     $   IX = 1 - ( N-1 )*INCX
      DMAX = DABS( DX( IX ) )
      IX = IX + INCX
      DO 20 I = 2, N
         IF( DABS( DX( IX ) ).LE.DMAX )
     $      GO TO 10
         IDAMAX = I
         DMAX = DABS( DX( IX ) )
   10    IX = IX + INCX
   20 CONTINUE
      IF( INCX.LT.0 )
     $   IDAMAX = N - IDAMAX + 1
      RETURN
*
*        code for increment equal to 1
*
   30 DMAX = DABS( DX( 1 ) )
      DO 40 I = 2, N
         IF( DABS( DX( I ) ).LE.DMAX )
     $      GO TO 40
         IDAMAX = I
         DMAX = DABS( DX( I ) )
   40 CONTINUE
      RETURN
      END
